#ifndef QEPDRIVER_H_
#define QEPDRIVER_H_

#define MATH_TYPE 1
#include "IQmathLib.h"         // Include header for IQmath library
#include "..\System\F2806x_Device.h"

// BLDC Index Setup

class QEPDriver
{	
private:
	// Position
 	Uint32 m_currentPosition; // QPOSCNT
	float m_ElecTheta; // electric angle
	float m_MechTheta; // mechanical angle
	int m_Direction; 		// Motor direction: 0=CCW/reverse, 1=CW/forward

	// State
	bool m_IndexLocked;
	Uint32 m_QepCountIndex;
	
	// Config
	Uint16 m_PolePairs;
	Uint16 m_EncoPPR;
	int32 m_CalibratedAngle;
	float m_MechScaler;
	float m_ToRadPerSec; // rad/s
	float m_ToRPM; // rad/s

	// Speed vars
	Uint32 m_lastLatchedPos; // old latched position;
	float m_SpeedFast;
	float m_SpeedSlow;

public:
	void Init(int encoPPR, int polePairs, int calibAngle);
	void Calc(void);
	float GetSpeedPulsesPerSec(void);
	float GetSpeedRads(void);
	float GetSpeedRPM(void);
	float GetPosition(void);
	float GetMechTheta(void);
	float GetElecTheta(void);
	bool IsIndexLocked(void);
	void SetCalibAngle(int32 calibAngle);
};

#endif /*  QEPDRIVER_H_ */

